package com.future.cb.common.utils;

import java.io.PrintWriter;

import javax.servlet.http.HttpServletResponse;

import com.fasterxml.jackson.databind.ObjectMapper;

public class RenderUtil {
	
	public static void RenderJson(HttpServletResponse response,Object jsonObject) {
		try {
			PrintWriter writer = null;
			response.setHeader("Pragma", "no-cache");	// HTTP/1.0 caches might not implement Cache-Control and might only implement Pragma: no-cache
			response.setHeader("Cache-Control", "no-cache");
			response.setDateHeader("Expires", 0);
			
			response.setContentType("application/json; charset=UTF-8");
			writer = response.getWriter();
			ObjectMapper mapper = new ObjectMapper();
			String jsonText = mapper.writeValueAsString(jsonObject);
			
			writer.write(jsonText);
			writer.flush();
		} catch (Exception e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	}
}
